package cn.tedu.tmall.admin.mall.dao.repository.impl;

import cn.tedu.tmall.admin.mall.dao.mapper.CategoryMapper;
import cn.tedu.tmall.admin.mall.dao.repository.ICategoryRepository;
import cn.tedu.tmall.admin.mall.pojo.po.CategoryPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class CategoryRepository implements ICategoryRepository {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public CategoryPO getCategoryById(Long categoryId) {
        return categoryMapper.selectById(categoryId);
    }

    @Override
    public Integer countCategoryByName(String name) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("name",name);
        Integer count = categoryMapper.selectCount(queryWrapper);
        return count;
    }

    @Override
    public void save(CategoryPO newcategoryPO) {
        categoryMapper.insert(newcategoryPO);
    }
}
